package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"strings"
)

func getHelmImage(imageFile string) (string, error) {
	file, err := os.Open(imageFile)
	if err != nil {
		fmt.Printf("Cannot open text file: %s, err: [%v]\n", imageFile, err)
		return "", err
	}
	defer file.Close()

	readStart := false
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.TrimSpace(line)
		if strings.Contains(line, "#helmchart") {
			readStart = true
		}
		if readStart {
			if line == "" || line[0] == '#' {
				continue
			} else {
				fmt.Println("-->", line, ":", len(line))
			}
		}
		//if strings.Contains(line, "#helmchart") {
		//	scanner.Scan()
		//	imageLine := scanner.Text()
		//	return imageLine, nil
		//}
	}

	if err := scanner.Err(); err != nil {
		fmt.Printf("Cannot scanner text file: %s, err: [%v]", imageFile, err)
		return "", err
	}

	return "", errors.New("helm image not found")
}


func main() {
	getHelmImage("config/images-kube.txt")

	return
}
